<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('人力资源成本')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
</head>
<style>
    select {
        padding-top: 3px !important;
    }

    .select-list {
        margin-top: 5px !important;
    }

    .select-list li p {
        width: auto !important;
        margin-top: 7px !important;
    }

    .form-header {
        margin: 10px auto !important;

    }

    .table-striped .table > thead:first-child > tr:first-child > th {
        font-weight: normal;
        font-size: 13px;
        border: 1px solid #cccccc;
        border-right: none;
        border-top: 1px solid #cccccc !important;
    }
</style>
<body class="gray-bg">
<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="project-form">
                    <div class="col-sm-12">
                        <div class="select-list">
                            <ul>
                                <li>
                                    <p>单位：</p>
                                    <select name="compId" id="compId" class="form-control">
                                        <option value="">请选择</option>
                                        <option th:each="pro:${userComp}" th:value="${pro.compId}"
                                                th:text="${pro.compName}"></option>
                                    </select>

                                </li>
                                <li>
                                    <p>年份：</p>
                                    <select name="years" id="years" class="form-control">
                                        <option value="">请选择</option>
                                        <option value="2020">2020</option>
                                        <option value="2021">2021</option>
                                        <option value="2022">2022</option>
                                        <option value="2023">2023</option>
                                        <option value="2024">2024</option>
                                        <option value="2025">2025</option>
                                    </select>
                                </li>
                                <li>
                                    <p>月份：</p>
                                    <select name="months" id="months" class="form-control">
                                        <option value="">请选择</option>
                                        <option value="1">一月</option>
                                        <option value="2">二月</option>
                                        <option value="3">三月</option>
                                        <option value="4">四月</option>
                                        <option value="5">五月</option>
                                        <option value="6">六月</option>
                                        <option value="7">七月</option>
                                        <option value="8">八月</option>
                                        <option value="9">九月</option>
                                        <option value="10">十月</option>
                                        <option value="11">十一月</option>
                                        <option value="12">十二月</option>
                                    </select>
                                </li>
                                <li>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                            class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                            class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </form>
            </div>
            <div class="col-sm-12 select-table table-striped">

                <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-primary single disabled" onclick="$.operate.edit()">
                        <i class="fa fa-edit"></i> 修改
                    </a>
                    <a class="btn btn-warning" onclick="exportEmpChange()">
                        <i class="fa fa-download"></i> 导出
                    </a>
                </div>
                <table id="humanreSources-table"></table>
                <div class="col-sm-12 sum"></div>
            </div>

        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<script th:inline="javascript">
    var prefix = ctx + 'humanResources';
    var value;
    $(function () {

        var humanResources_options = {
            url: prefix + '/list',
            uniqueId: "id",
            id: 'humanreSources-table',
            createUrl: prefix + "/add",
            removeUrl: prefix + "/remove",
            updateUrl: prefix + "/edit/{id}",
            modalName: "人力资源成本",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            pagination:false,
            rowStyle: function (row, index) {
                var style = {};
                style={css:{'color':'#ed5565','font-weight':'700'}};

                if(row.compName=='小计'){
                    return style;
                }else {
                    return '';
                }

            },
            columns: [
                [
                    {
                        checkbox: true,
                        rowspan: 2,
                        valign: "middle",
                        align: "center",

                    },
                    {
                        field: 'compName',
                        title: '工程公司名称',
                        rowspan: 2,
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'months',
                        title: '月份',
                        rowspan: 2,
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'years',
                        title: '年份',
                        rowspan: 2,
                        valign: "middle",
                        align: "center"
                    },
                    {
                        title: '工资支出(含社保、公积金)',
                        rowspan: 1,
                        colspan: 4,
                        align: "center"
                    },
                    {
                        title: '招聘支出',
                        rowspan: 1,
                        colspan: 3,
                        align: "center"
                    },
                    {
                        title: '培训支出',
                        rowspan: 1,
                        colspan: 3,
                        align: "center"
                    },
                    {
                        title: '其他活动或人资项目支出',
                        rowspan: 1,
                        colspan: 3,
                        align: "center"
                    },
                    {
                        title: '人力资源总成本支出(1月——当月)',
                        rowspan: 1,
                        colspan: 3,
                        align: "center"
                    },
                ],
                [
                    {
                        field: 'totalWages',
                        title: '总额(应发)',
                        align: "center"
                    },
                    {
                        field: 'monthEndNum',
                        title: '月末人数',
                        align: "center"
                    },
                    {
                        field: 'averageWages',
                        title: '人均工资',
                        align: "center"
                    },
                    {
                        field: 'lastMonthComparison',
                        title: '与上月比增加',
                        align: "center"
                    },

                    {
                        field: 'totalRecruit',
                        title: '总额',
                        align: "center"
                    },
                    {
                        field: 'positionNum',
                        title: '到岗人数',
                        align: "center"
                    },
                    {
                        field: 'averageRecruit',
                        title: '人均',
                        align: "center"
                    },
                    {
                        field: 'totalTrain',
                        title: '总额',
                        align: "center"
                    },
                    {
                        field: 'trainNum',
                        title: '人次',
                        align: "center"
                    },
                    {
                        field: 'averageTrain',
                        title: '人均',
                        align: "center"
                    },
                    {
                        field: 'totalOther',
                        title: '总额',
                        align: "center"
                    },
                    {
                        field: 'otherNum',
                        title: '人次',
                        align: "center"
                    },
                    {
                        field: 'averageOther',
                        title: '人均',
                        align: "center"
                    },
                    {
                        field: 'totalHuman',
                        title: '总额',
                        align: "center"
                    },
                    {
                        field: 'humanNum',
                        title: '平均人数',
                        align: "center"
                    },
                    {
                        field: 'averageHuman',
                        title: '人均成本',
                        align: "center"
                    },

                ],


            ]
        }
        $.table.init(humanResources_options);
        // sum();

    })

    // function sum() {
    //     setTimeout(function () {
    //         value = $("#humanreSources-table").bootstrapTable('getData');
    //         var totalWages = 0;//工资支出总额
    //         var monthEndNum = 0;//月末人数
    //         var averageWages = 0;//人均工资
    //         var lastMonthComparison = 0;//与上月比增加
    //         var totalRecruit = 0;//招聘支出总额
    //         var positionNum = 0;//到岗人数
    //         var averageRecruit = 0;//人均招聘支出
    //         var totalTrain = 0;//培训支出总额
    //         var trainNum = 0;//人次
    //         var averageTrain = 0;//人均培训支出
    //         var totalOther = 0;//其他活动或人资项目支出总额
    //         var otherNum = 0;//人次
    //         var averageOther = 0;//人均其他活动或人资项目支出
    //         var totalHuman = 0;//人力资源总成本支出总额
    //         var humanNum = 0;//人次
    //         var averageHuman = 0;//人均成本
    //
    //         for (var i in value) {
    //
    //             totalWages += value[i].totalWages;
    //             monthEndNum += value[i].monthEndNum;
    //             lastMonthComparison += value[i].lastMonthComparison;
    //             totalRecruit += value[i].totalRecruit;
    //             positionNum += value[i].positionNum;
    //             totalTrain += value[i].totalTrain;
    //             trainNum += value[i].trainNum;
    //             totalOther += value[i].totalOther;
    //             otherNum += value[i].otherNum;
    //             totalHuman += value[i].totalHuman;
    //             humanNum += value[i].humanNum;
    //
    //
    //         }
    //         if (value.length == 0||totalTrain==0) {
    //             averageWages = 0;//人均工资
    //             averageRecruit = 0;//人均招聘支出
    //             averageTrain = 0;//人均培训支出
    //             averageOther = 0;//人均其他活动或人资项目支出
    //             averageHuman = 0;//人均成本
    //         } else {
    //             averageWages=(totalWages/monthEndNum).toFixed(2);
    //             averageRecruit=(totalRecruit/positionNum).toFixed(2);
    //             averageTrain=(totalTrain/trainNum).toFixed(2);
    //             averageOther=(totalOther/otherNum).toFixed(2);
    //             averageHuman=(totalHuman/humanNum).toFixed(2);
    //         }
    //         var html;
    //         html = '<div class="col-sm-12" style="text-align: center;">' + '<h3 style="display: inline;">合计：</h3>' +
    //             '<div style="display: inline">' +
    //             "工资支出总额：" + '<sapan style="color: red;">' + totalWages + '</sapan>' + "；" +
    //             "月末人数：" + '<sapan style="color: red;">' + monthEndNum + '</sapan>' + "；" +
    //             "人均工资：" + '<sapan style="color: red;">' + averageWages + '</sapan>' + "；" +
    //             "与上月比增加：" + '<sapan style="color: red;">' + lastMonthComparison + '</sapan>' + "；" +
    //             "招聘支出总额：" + '<sapan style="color: red;">' + totalRecruit + '</sapan>' + "；" +
    //             "到岗人数：" + '<sapan style="color: red;">' + positionNum + '</sapan>' + "；" +
    //             "人均招聘支出：" + '<sapan style="color: red;">' + averageRecruit + '</sapan>' + "；" +
    //             "培训支出总额：" + '<sapan style="color: red;">' + totalTrain + '</sapan>' + "；" +
    //             "人次：" + '<sapan style="color: red;">' + trainNum + '</sapan>' + "；" +
    //             "人均培训支出：" + '<sapan style="color: red;">' + averageTrain + '</sapan>' + "；" +
    //             "其他活动或人资项目支出总额：" + '<sapan style="color: red;">' + totalOther + '</sapan>' + "；" +
    //             "人次：" + '<sapan style="color: red;">' + otherNum + '</sapan>' + "；" +
    //             "人均其他活动或人资项目支出：" + '<sapan style="color: red;">' + averageOther + '</sapan>' + "；" +
    //             "人力资源总成本支出总额：" + '<sapan style="color: red;">' + totalHuman + '</sapan>' + "；" +
    //             "人次：" + '<sapan style="color: red;">' + humanNum + '</sapan>' + "；" +
    //             "人均成本：" + '<sapan style="color: red;">' + averageHuman + '</sapan>' + "；" +
    //             '</div>' + '</div>';
    //         $(".sum").empty();
    //         $(".sum").append(html);
    //     }, 500);
    // }
    function exportEmpChange() {
        $('#humanreSources-table').bootstrapTable('hideColumn', 0);
        $("#humanreSources-table").tableExport({type: 'excel',
            fileName: '人力资源成本表',
            exportDataType: "all",
        });
        $('#humanreSources-table').bootstrapTable('showColumn', 0);
    }
</script>
</body>
</html>